import json
import os
from config.config import *
from collections import defaultdict

# json测试结果的存放目录

report_path = REPORT_PATH


def get_test_result_data():
    names = os.listdir(report_path)

    # result = {"passed":0, "failed":0, "unknow":0}

    result = defaultdict(int)

    for name in names:
        if name.endswith("result.json"):
            with open(os.path.join(report_path, name), "r", encoding="utf-8") as file:
                data = json.load(file)

                result[data.get("status", "unknow")] += 1
                # result[data.get("status", "unknow")] += 1
                # result[data.get("status", "unknow")] += 1

                # if data.get("status", "unknow") == "passed":
                #     result["passed"] += 1
                # elif data.get("status", "unknow") == "failed":
                #     result["failed"] += 1
                # elif data.get("status", "unknow") == "unknow":
                #     result["unknow"] += 1

    return result

